package com.spring.sunflower.common;

import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import androidx.constraintlayout.widget.ConstraintLayout;

import com.bumptech.glide.Glide;
import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.viewholder.BaseViewHolder;
import com.makeramen.roundedimageview.RoundedImageView;
import com.spring.sunflower.R;
import com.spring.sunflower.bean.ReportPicBean;
import com.spring.sunflower.util.DisplayUtils;

import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

import java.util.List;

/**
 * Created by Kevin on 2021/7/2<br/>
 * <p>
 * Describe:<br/>
 */
public class ReportPhotoAdapter extends BaseQuickAdapter<ReportPicBean, BaseViewHolder> {
    public ReportPhotoAdapter(int layoutResId, @Nullable List<ReportPicBean> data) {
        super(layoutResId, data);
    }

    @Override
    protected void convert(@NotNull BaseViewHolder baseViewHolder, ReportPicBean datasBean) {
        RoundedImageView image = baseViewHolder.getView(R.id.rivImage);
        TextView tvChecking = baseViewHolder.getView(R.id.tvChecking);
        ConstraintLayout.LayoutParams layoutParams = new ConstraintLayout.LayoutParams(-2, -2);
        int screenWidth = DisplayUtils.getScreenWidth(getContext());
        int i = DisplayUtils.dip2px(getContext(), 45);
        int imageWidth = (screenWidth - i) / 4;
        layoutParams.width = imageWidth;
        layoutParams.height = imageWidth;
        image.setLayoutParams(layoutParams);
        if (datasBean.isPlaceholder()) {
            Glide.with(getContext())
                    .load(R.drawable.ic_add)
                    .into((ImageView) image);
        } else {
            Glide.with(getContext())
                    .load(datasBean.getPicPath())
                    .into((ImageView) image);

        }
        RoundedImageView rivDelete = baseViewHolder.getView(R.id.rivDelete);
        rivDelete.setVisibility(datasBean.isShowDelete() && !datasBean.isPlaceholder() ? View.VISIBLE : View.GONE);
    }
}
